
<template>
  <Card style="width:100%" class="detail-content-layout mb16">
    <template #title>
     {{$t('需求定稿')}}
    </template>
    <template #extra>
      <div class="h-arrow-wrap" @click="toggle = !toggle">
        <i :class="{toggleActive:toggle}" class="iconfont zy-common-jiantou h-arrow-icon"></i>
      </div>
    </template>
    <transition name="slide-up">
      <div v-if="toggle">
        <Form ref="form" :model="form" :rules="rules" label-position="top">
          <Row :gutter="24">
            <Col span="6">
              <FormItem :label="$t('资产编号')" prop="assetNo">
                <Input maxlength="50" :disabled="disabled" clearable type="text" v-model="form.assetNo" :placeholder="$t('请输入')" ></Input>
              </FormItem>
            </Col>
            <Col span="6" class="autoHeight">
              <FormItem :label="$t('更新的规格说明书')" prop="specOuts">
                <uploadFile accept=".pdf,.doc,.docx" key="99" :fileList="info.specOuts" :disabled="disabled"
                            @change="(list)=>{form.specOuts = list}"/>
              </FormItem>
            </Col>
            <Col span="6">
              <FormItem :label="$t('备注')">
                <Input maxlength="200" :disabled="disabled" clearable type="text" v-model="form.remark" :placeholder="$t('请输入')" ></Input>
              </FormItem>
            </Col>
            <Col span="6">
              <FormItem  :label="$t('提交人')"   v-if="disabled">
                <Input disabled clearable type="text" v-model="form.submitByStr" :placeholder="$t('请输入')" ></Input>
              </FormItem>
            </Col>
            <Col span="6" v-if="disabled">
              <FormItem :label="$t('提交时间')">
                <Input disabled clearable type="text" v-model="form.submitTime" :placeholder="$t('请输入')" ></Input>
              </FormItem>
            </Col>
          </Row>
        </Form>
        <rejectInfo :rejectFlows="rejectFlows"/>
      </div>
    </transition>
  </Card>
</template>

<script>
import uploadFile from "@/views/devBasic/capex/components/uploadFile";
import mixins from "@/views/devBasic/capex/components/mixins";
import rejectInfo from "@/views/devBasic/capex/components/rejectInfo";
export default {
  name: "SpecOut",
  components:{uploadFile,rejectInfo},
  mixins:[mixins],
  props: {
    info: {
      type: Object,
      default: ()=> {}
    },
    disabled: {
      type: Boolean,
      default: false
    },
    approvalInfo:{
      type: Object,
      default: ()=> {}
    },
    rejectFlows: {
      type: Object,
      default: () => {
      }
    },
    expand:{
      type: Boolean,
      default: false
    }
  },
  data() {
    const validateFile = (rule, value, callback) => {
      if (!(Array.isArray(this.form.specOuts) && this.form.specOuts.length > 0)) {
        callback(new Error(this.$t('请上传附件')));
      } else {
        callback();
      }
    };
    return {
      toggle: true,
      form:{},
      rules:{
        specOuts: [{ required:true, validator: validateFile, trigger: 'change'}],
        assetNo :[{required: true, type: "string", message: this.$t('请输入'), trigger: 'change'}],
      }
    }
  },
  created() {
      console.log(this.info)
    if (this.info.assetNo)
      this.setParams()
    if (this.disabled) {
      this.toggle = false
    }else if (this.rejectFlows && this.rejectFlows.approvalRemark){
      this.toggle = true
    }
    if (this.expand){
      this.toggle = true
    }
  },
  methods:{
    setParams(){
      const {submitTime,submitRemark,submitByStr} = this.approvalInfo
      const {specOuts,assetNo} = this.info;
      this.form = Object.assign(this.form, {
        remark:submitRemark,
        submitTime,
        submitByStr,
        specOuts,
        assetNo
      })
      this.$forceUpdate()
    },
    async getParams(status) {
      const valid = status ? status:await this.$refs.form.validate()
      if (valid) {
        return {
          ...this.form
        }
      }
    }
  }
}
</script>

<style scoped lang="scss">
@import "./style";
</style>

